package com.atguigu;

import java.util.concurrent.*;

/**
 * @ClassName MyThreadPoolDemo
 * @Author yy
 * @create 2022/9/12 14:51
 */
public class MyThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService pool = new ThreadPoolExecutor(
                2,
                5,
                3,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        try {
            for (int i = 0; i < 8; i++) {
                int finalI = i;
                pool.execute(()->{
                    System.out.println(Thread.currentThread().getName() + "\t 处理业务" + "\t 顾客: " + finalI);
                });
            }
        }finally {
            pool.shutdown();
        }
    }
}
